{% extends "base.html" %}

{% block content %}
<div class="container">
    <h2>手动添加单词</h2>
    <form id="add-word-form">
        <div class="mb-3">
            <label for="word" class="form-label">输入单词</label>
            <input type="text" class="form-control" id="word" name="word" required>
        </div>
        <button type="submit" class="btn btn-primary">提交</button>
    </form>
    <div id="message" class="mt-3"></div>
</div>

{% block scripts %}
<script>
// let isSubmitting = false;

// document.getElementById('add-word-form').addEventListener('submit', function(e) {
//     e.preventDefault();
    
//     if (isSubmitting) return;  // 如果正在提交，则返回
//     isSubmitting = true;  // 设置为正在提交

//     const formData = new FormData(this);
    
//     fetch("/add_word111", {
//         method: 'POST',
//         body: formData
//     })
//     .then(response => response.json())
//     .then(data => {
//         const messageDiv = document.getElementById('message');
//         if (data.success) {
//             messageDiv.innerHTML = '<div class="alert alert-success">' + data.message + '</div>';
//             document.getElementById('add-word-form').reset();  // 清空表单
//         } else {
//             messageDiv.innerHTML = '<div class="alert alert-danger">添加单词失败，请重试。</div>';
//         }
//     })
//     .catch(error => {
//         console.error('Error:', error);
//         document.getElementById('message').innerHTML = '<div class="alert alert-danger">添加单词失败，请重试。</div>';
//     })
//     .finally(() => {
//         isSubmitting = false;  // 在请求完成后重置状态
//     });
// });
</script>
{% endblock %}
{% endblock %} 